package com.xjwlmq.exam20241011;

import com.alibaba.fastjson.JSON;
import com.xjwlmq.dx.entity.RainQuality;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;

/**
 * @ClassName DictTypeListServlet
 * @Description TODO:
 * @Author 12994
 * @Date 2024/10/11 20:35
 * @Version 1.0
 **/
@WebServlet("/getDictTypeList")
public class DictTypeListServlet extends HttpServlet {
    DictTypeDaoImpl dictTypeDao = new DictTypeDaoImpl();

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html:charset=UTF-8");

        if (req.getParameter("dict_id") != null) {
            ArrayList<DictType> dictTypes = dictTypeDao.getDictTypes(Integer.parseInt(req.getParameter("dict_id")));
            resp.getWriter().write(JSON.toJSONString(dictTypes));
        } else {
            ArrayList<DictType> dictTypes = dictTypeDao.getDictTypes();
            resp.getWriter().write(JSON.toJSONString(dictTypes));
        }
    }
}
